package cn.edu.scau.dao;

import cn.edu.scau.entity.DishCalender;

import java.util.Date;

import org.apache.ibatis.jdbc.SQL;

public class DishCalenderSqlProvider {

    public String insertSelective(DishCalender record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("dishcalender");
        
        if (record.getDishcalenderid() != null) {
            sql.VALUES("dishcalenderID", "#{dishcalenderid,jdbcType=INTEGER}");
        }
        
        if (record.getDishid() != null) {
            sql.VALUES("dishID", "#{dishid,jdbcType=INTEGER}");
        }
        
        if (record.getDishcalenderdate() != null) {
            sql.VALUES("dishcalenderDate", "#{dishcalenderdate,jdbcType=DATE}");
        }
        
        if (record.getDishcalendertime() != null) {
            sql.VALUES("dishcalenderTime", "#{dishcalendertime,jdbcType=VARCHAR}");
        }
        
        if (record.getDishcalenderamount() != null) {
            sql.VALUES("dishcalenderAmount", "#{dishcalenderamount,jdbcType=INTEGER}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(DishCalender record) {
        SQL sql = new SQL();
        sql.UPDATE("dishcalender");
        
        if (record.getDishid() != null) {
            sql.SET("dishID = #{dishid,jdbcType=INTEGER}");
        }
        
        if (record.getDishcalenderdate() != null) {
            sql.SET("dishcalenderDate = #{dishcalenderdate,jdbcType=DATE}");
        }
        
        if (record.getDishcalendertime() != null) {
            sql.SET("dishcalenderTime = #{dishcalendertime,jdbcType=VARCHAR}");
        }
        
        if (record.getDishcalenderamount() != null) {
            sql.SET("dishcalenderAmount = #{dishcalenderamount,jdbcType=INTEGER}");
        }
        
        sql.WHERE("dishcalenderID = #{dishcalenderid,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    
    public String findByDishcalenderdateDishcalendertime(Date dishcalenderdate,String dishcalendertime){
    	SQL sql = new SQL();
    	sql.SELECT("dishcalenderID, dishcalender.dishID, dishName ,dishcalenderDate, dishcalenderTime, dishcalenderAmount");
    	sql.FROM("dishcalender,dish");
    	if(dishcalenderdate!=null) {
    		sql.WHERE(" dishcalenderDate like concat('%',#{dishcalenderdate},'%')");
    	}
    	if(dishcalendertime!=null) {
    		sql.WHERE(" dishcalenderTime like concat('%',#{dishcalendertime},'%')");
    	}
    	sql.WHERE("dishcalender.dishID = dish.dishID");
    	return sql.toString();
    }
}